// 第一题

let request = function(value) {
    console.log('请求的数据:', value);
};

// 防抖
const debounce = function(fn, delay = 500) {
    let timer = null;
    let content = this;
    return function(...ags) {
        if(timer) {
            clearTimeout(timer);
            timer = null;
        } else {
            fn.apply(content, ags);
        };
        timer = setTimeout(() => {
            fn.apply(content, ags);
        }, delay);
    }
}

const inputFn = function (e) {
    let value = e.target.value;
    request(value);
}
document.querySelector("#debouce").oninput = debounce(inputFn, 1000);